package com.pureut.production.controller;

import com.pureut.common.core.web.controller.BaseController;
import com.pureut.common.core.web.domain.AjaxResult;
import com.pureut.common.core.web.page.TableDataInfo;
import com.pureut.common.log.annotation.Log;
import com.pureut.common.log.enums.BusinessType;
import com.pureut.common.security.annotation.RequiresPermissions;
import com.pureut.production.domain.dto.CutFeedDto;
import com.pureut.production.domain.dto.CutOrdersDocumentDto;
import com.pureut.production.domain.vo.*;
import com.pureut.production.service.CutOrdersDocumentService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/***
 * 分切制令单控制层
 * Author:C
 * Date:2023/02/16 10:18
 * @DESC
 */
@RestController
@RequestMapping("/cut-orders-document")
public class CutOrdersDocumentController extends BaseController {

    @Resource
    CutOrdersDocumentService cutOrdersDocumentService;

    /**
     * 分切制令单列表
     */
    @RequiresPermissions("productionTube:produAdm:slitting:prepara:list")
    @GetMapping("/list")
    public TableDataInfo selectOperationList(CutOrdersDocumentVo cutOrdersDocumentVo) {
        startPage();
        // 查询分切制令单列表
        List<CutOrdersDocumentDto> list = cutOrdersDocumentService.getList(cutOrdersDocumentVo);
        return getDataTable(list);
    }

    /**
     * 是否免检修改（1：开，2：关）
     */
    @RequiresPermissions("productionTube:produAdm:slitting:prepara:switch")
    @PutMapping("/switch")
    @Log(title = "是否免检修改", businessType = BusinessType.UPDATE)
    public AjaxResult getSwitch(@RequestBody SwitchVo switchVo) {
        return toAjax(cutOrdersDocumentService.getSwitch(switchVo));
    }

    /**
     * 查看
     */
    @RequiresPermissions("productionTube:produAdm:slitting:prepara:query")
    @GetMapping("/view/{id}")
    public AjaxResult getView(@PathVariable("id") Long id) {
        return AjaxResult.success(cutOrdersDocumentService.getViewById(id));
    }

    /**
     * 上线
     */
    @RequiresPermissions("productionTube:produAdm:slitting:prepara:goOnline")
    @PostMapping("/goOnline")
    @Log(title = "上线", businessType = BusinessType.UPDATE)
    public AjaxResult goOnline(@RequestBody CutOrdersDocumentVo cutOrdersDocumentVo) {
        return toAjax(cutOrdersDocumentService.goOnline(cutOrdersDocumentVo));
    }

    /**
     * 分切完成
     */
    @RequiresPermissions("productionTube:produAdm:slitting:prepara:accomplish")
    @PostMapping("/slittingCompletion")
    @Log(title = "分切完成", businessType = BusinessType.UPDATE)
    public AjaxResult slittingCompletion(@RequestBody SlittingCompletionVo slittingCompletionVo) throws Exception {
        return AjaxResult.success(cutOrdersDocumentService.slittingCompletion(slittingCompletionVo));
    }

    /**
     * 分卷
     */
    @RequiresPermissions("productionTube:produAdm:slitting:prepara:subsection")
    @PostMapping("/subVolume")
    @Log(title = "分卷", businessType = BusinessType.UPDATE)
    public AjaxResult subVolume(@RequestBody SubVolumeVo subVolumeVo) throws Exception {
        return AjaxResult.success(cutOrdersDocumentService.subVolume(subVolumeVo));
    }

    /**
     * 停产
     */
    @RequiresPermissions("productionTube:produAdm:slitting:prepara:stop")
    @GetMapping("/stopProduction/{id}")
    @Log(title = "停产", businessType = BusinessType.UPDATE)
    public AjaxResult stopProduction(@PathVariable("id") Long id) {
        return toAjax(cutOrdersDocumentService.stopProduction(id));
    }

    /**
     * 单据完成
     */
    @RequiresPermissions("productionTube:produAdm:slitting:prepara:completion")
    @GetMapping("/completionDocuments/{id}")
    @Log(title = "单据完成", businessType = BusinessType.UPDATE)
    public AjaxResult completionDocuments(@PathVariable("id") Long id) {
        return toAjax(cutOrdersDocumentService.completionDocuments(id));
    }

    /**
     * 关结
     */
    @RequiresPermissions("productionTube:produAdm:slitting:prepara:close")
    @PostMapping("/close")
    @Log(title = "关结", businessType = BusinessType.UPDATE)
    public AjaxResult close(@RequestBody CloseVo closeVo) {
        return toAjax(cutOrdersDocumentService.close(closeVo));
    }

    /**
     * 查询水刺及分切数据
     */
    @GetMapping("/selectCombinationList")
    public AjaxResult selectCombinationList(SelectCombinationListVo selectCombinationListVo) {
        return AjaxResult.success(cutOrdersDocumentService.selectCombinationList(selectCombinationListVo));
    }

    /**
     * 废料打印
     */
    @RequiresPermissions("productionTube:produAdm:slitting:prepara:printing")
    @PostMapping("/wastePrint")
    @Log(title = "废料打印", businessType = BusinessType.INSERT)
    public AjaxResult wastePrint(@RequestBody WasteTubeVo wasteTubeVo) throws Exception {
        return toAjax(cutOrdersDocumentService.wastePrint(wasteTubeVo));
    }

    /**
     * 新增
     */
    @PostMapping("/add")
    @RequiresPermissions("cut:orders:document:add")
    @Log(title = "新增", businessType = BusinessType.INSERT)
    public AjaxResult add(@RequestBody CutOrdersDocumentVo cutOrdersDocumentVo) throws Exception {
        return toAjax(cutOrdersDocumentService.add(cutOrdersDocumentVo));
    }

    /**
     * 手持pda 投料列表
     */
    @GetMapping("/cutFeedList")
    public TableDataInfo cutFeedList(CutFeedVo cutFeedVo) {
        startPage();
        // 查询分切制令单列表
        List<CutFeedDto> list = cutOrdersDocumentService.cutFeedList(cutFeedVo);
        return getDataTable(list);
    }

    /**
     * 手持pda 投料详情
     */
    @GetMapping("/cutFeedView")
    public AjaxResult cutFeedView(int number, Long id) {

        return AjaxResult.success(cutOrdersDocumentService.cutFeedView(number, id));
    }

    /**
     * 通过id线别名称及编码
     */
    @GetMapping("/getDataLineTypeName")
    public AjaxResult getDataLineTypeName(Long id) {
        return AjaxResult.success(cutOrdersDocumentService.getDataLineTypeName(id));
    }

    /**
     * 通过阶别，线别编码查询生产中的制令单号
     */
    @GetMapping("/getOrderNum")
    public AjaxResult getOrderNum(GetOrderNumVo getOrderNumVo) {
        return AjaxResult.success(cutOrdersDocumentService.getOrderNum(getOrderNumVo));
    }
}
